package com.yycx.module.bus.provider.handler.haiying.tasktodo.settle;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.PageInterceptor;
import com.yycx.common.mybatis.model.PageParams;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.admin.client.entity.BaseUser;
import com.yycx.module.admin.provider.mapper.BaseUserDeptMapper;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.entity.BusSaleman;
import com.yycx.module.bus.client.enums.AmountTypeEnum;
import org.flowable.engine.TaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 结算支付单列表
 *
 * @author zyf
 */
@Component
public class InvoiceSettlePayPaymentPageListHandler implements PageInterceptor<BusPayment> {

    @Resource
    private BaseUserDeptMapper userDeptMapper;

    @Autowired
    private TaskService taskService;

    @Override
    public void prepare(CriteriaQuery<BusPayment> cq, PageParams pageParams, EntityMap params) {
        //开票ID
        String paymentId = params.get("settleInvoiceId");
        cq.select(BusPayment.class, "*");
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        cq.addSelect(BusSaleman.class, "saleManName");
        cq.eq(true, "amountType", AmountTypeEnum.Settle.getCode());
        cq.eq(true, "payment.parentId", paymentId);
        cq.ge(FlymeUtils.isNotEmpty(beginDate), "payDate", beginDate);
        cq.le(FlymeUtils.isNotEmpty(endDate), "payDate", endDate);
        cq.createJoin(BusSaleman.class);
        cq.orderByDesc("payment.createTime");
    }


}
